package Fishbowl_test;
import java.util.ArrayList;


public class FishA extends Fish {
	public FishA(int x, int y) {
		super(x, y);
	}

	static int minToReproduce, maxToDie;

	@Override
	public void simulate() {
		if(fishbowl.getCell(this.x, this.y) != 1) {
			this.isAlive = false;
			return;
		}
		ArrayList<Integer> neighbours = Fish.fishbowl.getNeighborhood(this.x, this.y, 0);
		
		if(neighbours.size() > 0) {
			int index = Fishbowl.gen.nextInt(neighbours.size());
			this.starvation = 0;
			if(this.food == FishA.minToReproduce) {
				this.food = 0;
				fishbowl.setCell(this.x + Fishbowl.directions[neighbours.get(index)][0], 
						this.y + Fishbowl.directions[neighbours.get(index)][1], 1);
				fishbowl.addNewFish(new FishA(this.x + Fishbowl.directions[neighbours.get(index)][0],
						this.y + Fishbowl.directions[neighbours.get(index)][1]));
			} else {
				this.food++;
				fishbowl.setCell(this.x, this.y, 0);
				this.x += Fishbowl.directions[neighbours.get(index)][0];
				this.y += Fishbowl.directions[neighbours.get(index)][1];
				fishbowl.setCell(this.x, this.y, 1);
				
			}
		} else {
			this.food = 0;
			this.starvation++;
			if(this.starvation == FishA.maxToDie) {
				fishbowl.setCell(this.x, this.y, 0);
				this.isAlive = false;
			}
		}		
	}
}
